package c.j.a.c.y.a;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Build.VERSION;
import android.util.Log;
import android.util.SparseArray;
import c.j.a.c.g.y;
import c.j.a.d.b.d.g0;
import c.j.a.d.b.d.p;
import c.j.a.d.b.d.q;
import c.j.a.d.b.e.b;
import c.j.a.d.b.l.a;
import com.huawei.agconnect.exception.AGCServerException;
import com.huawei.hms.adapter.internal.BaseCode;
import com.huawei.hms.adapter.internal.CommonCode.MapKey;
import com.huawei.hms.jos.games.ranking.RankingConst;
import com.huawei.hms.support.api.entity.common.CommonConstant.ReqAccessTokenParam;
import com.huawei.hms.support.api.entity.pay.HwPayConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import com.ss.android.socialbase.downloader.g.c;
import f.r;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;

/* compiled from: InstallGuideHelper */
public class i {
    public static int A(String str) {
        try {
            return b.a().getResources().getIdentifier(str, "color", b.a().getPackageName());
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static int B() {
        return z("appdownloader_download_success");
    }

    public static int C() {
        return z("appdownloader_download_text");
    }

    public static int D() {
        return z("appdownloader_action");
    }

    public static boolean E(String str) {
        return (str.equals("GET") || str.equals("HEAD")) ? false : true;
    }

    public static String F(r rVar) {
        String f = rVar.f();
        String h = rVar.h();
        if (h == null) {
            return f;
        }
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(f);
        stringBuilder.append('?');
        stringBuilder.append(h);
        return stringBuilder.toString();
    }

    public static int G() {
        try {
            return b("appdownloader_action_new_bg", b.a().getPackageName());
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static int H(String str, Throwable th) {
        return Log.w("greenDAO", str, th);
    }

    public static int a(Context context, String str) {
        try {
            return context.getResources().getIdentifier(str, "string", context.getPackageName());
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static int b(String str, String str2) {
        try {
            return b.a().getResources().getIdentifier(str, "drawable", str2);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static PackageInfo c(Context context, File file, int i) {
        Context context2;
        PackageInfo packageInfo = null;
        if (a.f.b("getpackageinfo_by_reflect", 0) == 1) {
            Object h;
            Object g;
            String absolutePath = file.getAbsolutePath();
            try {
                h = h("android.content.pm.PackageParser", null);
            } catch (Exception unused) {
                h = null;
            }
            try {
                File file2 = new File(absolutePath);
                g = g(h, "parsePackage", new Object[]{file2, Integer.valueOf(0)});
            } catch (Exception unused2) {
                g = null;
            }
            if (g != null) {
                int i2;
                PackageInfo f;
                if (i != 0) {
                    i2 = (i & 786432) != 0 ? i : 786432 | i;
                    try {
                        f = f(h, g, i2);
                    } catch (Exception e) {
                        e.getMessage();
                        context2 = b.a;
                    }
                } else {
                    i2 = i;
                    f = null;
                }
                if (f == null) {
                    f = e(g, i2);
                }
                packageInfo = f;
            }
            if (packageInfo == null) {
                context2 = b.a;
            }
        }
        if (packageInfo != null) {
            return packageInfo;
        }
        PackageInfo v;
        if (!s(268435456) || VERSION.SDK_INT >= 26) {
            v = v(context, file, i);
        } else {
            try {
                v = d(file);
            } catch (Throwable th) {
                th.getMessage();
                context2 = b.a;
                v = v(context, file, i);
            }
        }
        return v;
    }

    /* JADX WARNING: Removed duplicated region for block: B:92:0x010b A:{SYNTHETIC, Splitter:B:92:0x010b} */
    /* JADX WARNING: Removed duplicated region for block: B:96:0x0112 A:{SYNTHETIC, Splitter:B:96:0x0112} */
    /* JADX WARNING: Removed duplicated region for block: B:100:0x0119 A:{SYNTHETIC, Splitter:B:100:0x0119} */
    /* JADX WARNING: Missing exception handler attribute for start block: B:88:0x0104 */
    /* JADX WARNING: Removed duplicated region for block: B:143:0x019f A:{SYNTHETIC, Splitter:B:143:0x019f} */
    /* JADX WARNING: Removed duplicated region for block: B:139:0x0198 A:{SYNTHETIC, Splitter:B:139:0x0198} */
    /* JADX WARNING: Removed duplicated region for block: B:143:0x019f A:{SYNTHETIC, Splitter:B:143:0x019f} */
    /* JADX WARNING: Failed to process nested try/catch */
    public static android.content.pm.PackageInfo d(java.io.File r13) {
        /*
        r0 = 0;
        r1 = android.os.Build.VERSION.SDK_INT;	 Catch:{ all -> 0x0161 }
        r2 = 24;
        r3 = "AndroidManifest.xml";
        if (r1 < r2) goto L_0x0042;
    L_0x0009:
        r1 = new java.io.FileInputStream;	 Catch:{ all -> 0x0161 }
        r1.<init>(r13);	 Catch:{ all -> 0x0161 }
        r13 = new java.util.zip.ZipInputStream;	 Catch:{ all -> 0x003c }
        r13.<init>(r1);	 Catch:{ all -> 0x003c }
    L_0x0013:
        r2 = r13.getNextEntry();	 Catch:{ all -> 0x003c }
        if (r2 == 0) goto L_0x0036;
    L_0x0019:
        r4 = r2.isDirectory();	 Catch:{ all -> 0x003c }
        if (r4 == 0) goto L_0x0023;
    L_0x001f:
        r13.closeEntry();	 Catch:{ all -> 0x0013 }
        goto L_0x0013;
    L_0x0023:
        r4 = r2.getName();	 Catch:{ all -> 0x003c }
        r4 = r3.equals(r4);	 Catch:{ all -> 0x003c }
        if (r4 != 0) goto L_0x0031;
    L_0x002d:
        r13.closeEntry();	 Catch:{ all -> 0x0013 }
        goto L_0x0013;
    L_0x0031:
        r4 = r0;
        r5 = r2;
        r2 = r1;
        r1 = r13;
        goto L_0x0077;
    L_0x0036:
        r4 = r0;
        r5 = r2;
        r2 = r1;
        r1 = r13;
        r13 = r4;
        goto L_0x0077;
    L_0x003c:
        r13 = move-exception;
        r4 = r0;
        r2 = r1;
        r1 = r4;
        goto L_0x0165;
    L_0x0042:
        r1 = new java.util.zip.ZipFile;	 Catch:{ all -> 0x0161 }
        r1.<init>(r13);	 Catch:{ all -> 0x0161 }
        r13 = r1.entries();	 Catch:{ all -> 0x015c }
        r2 = r0;
    L_0x004c:
        r4 = r13.hasMoreElements();	 Catch:{ all -> 0x015c }
        if (r4 == 0) goto L_0x0072;
    L_0x0052:
        r2 = r13.nextElement();	 Catch:{ all -> 0x015c }
        r2 = (java.util.zip.ZipEntry) r2;	 Catch:{ all -> 0x015c }
        r4 = r2.isDirectory();	 Catch:{ all -> 0x015c }
        if (r4 == 0) goto L_0x005f;
    L_0x005e:
        goto L_0x004c;
    L_0x005f:
        r4 = r2.getName();	 Catch:{ all -> 0x015c }
        r4 = r3.equals(r4);	 Catch:{ all -> 0x015c }
        if (r4 != 0) goto L_0x006a;
    L_0x0069:
        goto L_0x004c;
    L_0x006a:
        r13 = r1.getInputStream(r2);	 Catch:{ all -> 0x015c }
        r4 = r1;
        r5 = r2;
        r1 = r0;
        goto L_0x0076;
    L_0x0072:
        r13 = r0;
        r4 = r1;
        r5 = r2;
        r1 = r13;
    L_0x0076:
        r2 = r1;
    L_0x0077:
        if (r5 == 0) goto L_0x014f;
    L_0x0079:
        r5 = r5.getName();	 Catch:{ all -> 0x0157 }
        r3 = r3.equals(r5);	 Catch:{ all -> 0x0157 }
        if (r3 == 0) goto L_0x014f;
    L_0x0083:
        r3 = new c.j.a.d.a.k.a.a;	 Catch:{ all -> 0x0157 }
        r3.m6391init();	 Catch:{ all -> 0x0157 }
        r3.b();	 Catch:{ all -> 0x013c }
        r5 = 0;
        if (r13 == 0) goto L_0x0095;
    L_0x008e:
        r6 = new c.j.a.d.a.k.a.c;	 Catch:{ all -> 0x013c }
        r6.m2346init(r13, r5);	 Catch:{ all -> 0x013c }
        r3.a = r6;	 Catch:{ all -> 0x013c }
    L_0x0095:
        r6 = r3.a;	 Catch:{ all -> 0x013c }
        if (r6 == 0) goto L_0x0143;
    L_0x0099:
        r3.e();	 Catch:{ IOException -> 0x013e }
        r6 = r3.f;	 Catch:{ IOException -> 0x013e }
        r7 = 1;
        if (r6 == r7) goto L_0x0134;
    L_0x00a1:
        r7 = 2;
        if (r6 != r7) goto L_0x0095;
    L_0x00a4:
        if (r6 == r7) goto L_0x00a8;
    L_0x00a6:
        r6 = -1;
        goto L_0x00ad;
    L_0x00a8:
        r6 = r3.h;	 Catch:{ all -> 0x013c }
        r6 = r6.length;	 Catch:{ all -> 0x013c }
        r6 = r6 / 5;
    L_0x00ad:
        r5 = r0;
        r7 = r5;
        r8 = 0;
    L_0x00b0:
        if (r8 == r6) goto L_0x00e7;
    L_0x00b2:
        r9 = "versionName";
        r10 = r3.a(r8);	 Catch:{ all -> 0x013c }
        r9 = r9.equals(r10);	 Catch:{ all -> 0x013c }
        if (r9 == 0) goto L_0x00c3;
    L_0x00be:
        r5 = i(r3, r8);	 Catch:{ all -> 0x013c }
        goto L_0x00e4;
    L_0x00c3:
        r9 = "versionCode";
        r10 = r3.a(r8);	 Catch:{ all -> 0x013c }
        r9 = r9.equals(r10);	 Catch:{ all -> 0x013c }
        if (r9 == 0) goto L_0x00d4;
    L_0x00cf:
        r0 = i(r3, r8);	 Catch:{ all -> 0x013c }
        goto L_0x00e4;
    L_0x00d4:
        r9 = "package";
        r10 = r3.a(r8);	 Catch:{ all -> 0x013c }
        r9 = r9.equals(r10);	 Catch:{ all -> 0x013c }
        if (r9 == 0) goto L_0x00e4;
    L_0x00e0:
        r7 = i(r3, r8);	 Catch:{ all -> 0x013c }
    L_0x00e4:
        r8 = r8 + 1;
        goto L_0x00b0;
    L_0x00e7:
        r8 = -1;
        r10 = java.lang.Long.parseLong(r0);	 Catch:{ b -> 0x00ee }
        goto L_0x00ef;
    L_0x00ee:
        r10 = r8;
    L_0x00ef:
        r6 = (r10 > r8 ? 1 : (r10 == r8 ? 0 : -1));
        if (r6 == 0) goto L_0x011d;
    L_0x00f3:
        r0 = new android.content.pm.PackageInfo;	 Catch:{ all -> 0x013c }
        r0.<init>();	 Catch:{ all -> 0x013c }
        r0.versionName = r5;	 Catch:{ all -> 0x013c }
        r5 = (int) r10;	 Catch:{ all -> 0x013c }
        r0.versionCode = r5;	 Catch:{ all -> 0x013c }
        r0.packageName = r7;	 Catch:{ all -> 0x013c }
        if (r1 == 0) goto L_0x0104;
    L_0x0101:
        r1.closeEntry();	 Catch:{ all -> 0x0104 }
    L_0x0104:
        r3.b();	 Catch:{ all -> 0x0108 }
        goto L_0x0109;
    L_0x0109:
        if (r13 == 0) goto L_0x0110;
    L_0x010b:
        r13.close();	 Catch:{ all -> 0x010f }
        goto L_0x0110;
    L_0x0110:
        if (r4 == 0) goto L_0x0117;
    L_0x0112:
        r4.close();	 Catch:{ all -> 0x0116 }
        goto L_0x0117;
    L_0x0117:
        if (r2 == 0) goto L_0x011c;
    L_0x0119:
        r2.close();	 Catch:{ all -> 0x011c }
    L_0x011c:
        return r0;
    L_0x011d:
        r1 = new c.j.a.d.a.k.a.b;	 Catch:{ all -> 0x013c }
        r5 = new java.lang.StringBuilder;	 Catch:{ all -> 0x013c }
        r5.<init>();	 Catch:{ all -> 0x013c }
        r6 = "versionCode获取失败: ";
        r5.append(r6);	 Catch:{ all -> 0x013c }
        r5.append(r0);	 Catch:{ all -> 0x013c }
        r0 = r5.toString();	 Catch:{ all -> 0x013c }
        r1.m2345init(r0);	 Catch:{ all -> 0x013c }
        throw r1;	 Catch:{ all -> 0x013c }
    L_0x0134:
        r0 = new c.j.a.d.a.k.a.b;	 Catch:{ all -> 0x013c }
        r1 = "已达到END_DOCUMENT";
        r0.m2345init(r1);	 Catch:{ all -> 0x013c }
        throw r0;	 Catch:{ all -> 0x013c }
    L_0x013c:
        r0 = move-exception;
        goto L_0x014b;
    L_0x013e:
        r0 = move-exception;
        r3.b();	 Catch:{ all -> 0x013c }
        throw r0;	 Catch:{ all -> 0x013c }
    L_0x0143:
        r1 = new c.j.a.d.a.k.a.f;	 Catch:{ all -> 0x013c }
        r5 = "Parser is not opened.";
        r1.m2348init(r5, r3, r0);	 Catch:{ all -> 0x013c }
        throw r1;	 Catch:{ all -> 0x013c }
    L_0x014b:
        r1 = r13;
        r13 = r0;
        r0 = r3;
        goto L_0x0165;
    L_0x014f:
        r1 = new c.j.a.d.a.k.a.b;	 Catch:{ all -> 0x0157 }
        r3 = "没有找到AndroidManifest.xml entry";
        r1.m2345init(r3);	 Catch:{ all -> 0x0157 }
        throw r1;	 Catch:{ all -> 0x0157 }
    L_0x0157:
        r1 = move-exception;
        r12 = r1;
        r1 = r13;
        r13 = r12;
        goto L_0x0165;
    L_0x015c:
        r13 = move-exception;
        r2 = r0;
        r4 = r1;
        r1 = r2;
        goto L_0x0165;
    L_0x0161:
        r13 = move-exception;
        r1 = r0;
        r2 = r1;
        r4 = r2;
    L_0x0165:
        r3 = new c.j.a.d.a.k.a.b;	 Catch:{ all -> 0x0187 }
        r5 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0187 }
        r5.<init>();	 Catch:{ all -> 0x0187 }
        r6 = "throwable: ";
        r5.append(r6);	 Catch:{ all -> 0x0187 }
        r6 = r13.getMessage();	 Catch:{ all -> 0x0187 }
        r5.append(r6);	 Catch:{ all -> 0x0187 }
        r13 = r13.toString();	 Catch:{ all -> 0x0187 }
        r5.append(r13);	 Catch:{ all -> 0x0187 }
        r13 = r5.toString();	 Catch:{ all -> 0x0187 }
        r3.m2345init(r13);	 Catch:{ all -> 0x0187 }
        throw r3;	 Catch:{ all -> 0x0187 }
    L_0x0187:
        r13 = move-exception;
        if (r0 == 0) goto L_0x018f;
    L_0x018a:
        r0.b();	 Catch:{ all -> 0x018e }
        goto L_0x018f;
    L_0x018f:
        if (r1 == 0) goto L_0x0196;
    L_0x0191:
        r1.close();	 Catch:{ all -> 0x0195 }
        goto L_0x0196;
    L_0x0196:
        if (r4 == 0) goto L_0x019d;
    L_0x0198:
        r4.close();	 Catch:{ all -> 0x019c }
        goto L_0x019d;
    L_0x019d:
        if (r2 == 0) goto L_0x01a2;
    L_0x019f:
        r2.close();	 Catch:{ all -> 0x01a2 }
    L_0x01a2:
        throw r13;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.y.a.i.d(java.io.File):android.content.pm.PackageInfo");
    }

    public static PackageInfo e(Object obj, int i) throws Exception {
        PackageInfo packageInfo = new PackageInfo();
        String str = (String) obj.getClass().getField(ReqAccessTokenParam.PACKAGE_NAME).get(obj);
        if (str != null) {
            packageInfo.packageName = str;
        }
        str = (String) obj.getClass().getField("mVersionName").get(obj);
        if (str != null) {
            packageInfo.versionName = str;
        }
        packageInfo.versionCode = ((Integer) obj.getClass().getField("mVersionCode").get(obj)).intValue();
        if ((i & 4096) != 0) {
            ArrayList arrayList = (ArrayList) obj.getClass().getField("requestedPermissions").get(obj);
            if (arrayList != null) {
                packageInfo.requestedPermissions = (String[]) arrayList.toArray(new String[0]);
            }
        }
        packageInfo.applicationInfo = (ApplicationInfo) obj.getClass().getField("applicationInfo").get(obj);
        return packageInfo;
    }

    public static PackageInfo f(Object obj, Object obj2, int i) {
        try {
            Class cls = obj.getClass();
            cls.getMethods();
            Class cls2 = Class.forName("android.content.pm.PackageUserState");
            Object newInstance = cls2.getConstructor(new Class[0]).newInstance(new Object[0]);
            r6 = new Class[7];
            Class cls3 = Long.TYPE;
            r6[3] = cls3;
            r6[4] = cls3;
            r6[5] = Set.class;
            r6[6] = cls2;
            return (PackageInfo) cls.getMethod("generatePackageInfo", r6).invoke(null, new Object[]{obj2, null, Integer.valueOf(i), Long.valueOf(0), Long.valueOf(0), null, newInstance});
        } catch (Exception unused) {
            return null;
        }
    }

    public static Object g(Object obj, String str, Object[] objArr) throws Exception {
        Class cls = obj.getClass();
        Class[] clsArr = new Class[objArr.length];
        int length = objArr.length;
        for (int i = 0; i < length; i++) {
            clsArr[i] = objArr[i].getClass();
            if (clsArr[i] == Integer.class) {
                clsArr[i] = Integer.TYPE;
            } else if (clsArr[i] == Boolean.class) {
                clsArr[i] = Boolean.TYPE;
            }
        }
        return cls.getMethod(str, clsArr).invoke(obj, objArr);
    }

    public static Object h(String str, Object[] objArr) throws Exception {
        return Class.forName(str).getConstructor(null).newInstance(null);
    }

    public static String i(c.j.a.d.a.k.a.a aVar, int i) {
        int i2 = aVar.h[aVar.c(i) + 3];
        int i3 = aVar.h[aVar.c(i) + 4];
        String str = "";
        if (i2 == 3) {
            i = aVar.c(i);
            int[] iArr = aVar.h;
            if (iArr[i + 3] == 3) {
                str = aVar.c.a(iArr[i + 2]);
            } else {
                int i4 = iArr[i + 4];
            }
            return str;
        } else if (i2 == 2) {
            Object[] objArr = new Object[2];
            if ((i3 >>> 24) == 1) {
                str = "android:";
            }
            objArr[0] = str;
            objArr[1] = Integer.valueOf(i3);
            return String.format("?%s%08X", objArr);
        } else if (i2 >= 16 && i2 <= 31) {
            return String.valueOf(i3);
        } else {
            return String.format("<0x%X, type 0x%02X>", new Object[]{Integer.valueOf(i3), Integer.valueOf(i2)});
        }
    }

    public static StringBuilder j(StringBuilder stringBuilder, String str, String[] strArr) {
        for (int i = 0; i < strArr.length; i++) {
            String str2 = strArr[i];
            stringBuilder.append(str);
            stringBuilder.append(".\"");
            stringBuilder.append(str2);
            stringBuilder.append('\"');
            stringBuilder.append("=?");
            if (i < strArr.length - 1) {
                stringBuilder.append(',');
            }
        }
        return stringBuilder;
    }

    public static JSONObject k(String str, c cVar, com.ss.android.socialbase.downloader.e.a aVar, int i) {
        JSONObject jSONObject;
        JSONException e;
        try {
            jSONObject = new JSONObject();
            try {
                Context context = b.a;
                synchronized (b.class) {
                }
                jSONObject.put("event_page", str);
                jSONObject.put(HiAnalyticsConstant.BI_KEY_APP_ID, "");
                jSONObject.put("device_id", "");
                jSONObject.put("device_id_postfix", "");
                int i2 = 0;
                jSONObject.put(MapKey.UPDATE_VERSION, 0);
                jSONObject.put("download_status", i);
                if (cVar != null) {
                    jSONObject.put("download_id", cVar.g0());
                    jSONObject.put(RankingConst.RANKING_JGW_NAME, cVar.b);
                    jSONObject.put(HwPayConstant.KEY_URL, cVar.d);
                    jSONObject.put("download_time", cVar.X);
                    jSONObject.put("cur_bytes", cVar.I());
                    jSONObject.put("total_bytes", cVar.T);
                    jSONObject.put("network_quality", cVar.O);
                    jSONObject.put("only_wifi", cVar.g ? 1 : 0);
                    jSONObject.put("need_https_degrade", cVar.v ? 1 : 0);
                    jSONObject.put("https_degrade_retry_used", cVar.b0 ? 1 : 0);
                    jSONObject.put("md5", cVar.y);
                    jSONObject.put("chunk_count", cVar.R);
                    jSONObject.put("is_force", cVar.o ? 1 : 0);
                    jSONObject.put("retry_count", cVar.m);
                    jSONObject.put("cur_retry_time", cVar.F);
                    jSONObject.put("need_retry_delay", cVar.A ? 1 : 0);
                    jSONObject.put("need_reuse_first_connection", cVar.H ? 1 : 0);
                    jSONObject.put("default_http_service_backup", cVar.C ? 1 : 0);
                    jSONObject.put("retry_delay_status", cVar.G.ordinal());
                    jSONObject.put("backup_url_used", cVar.Z ? 1 : 0);
                    jSONObject.put("download_byte_error_retry_status", cVar.k0.ordinal());
                    jSONObject.put("forbidden_handler_status", cVar.I.ordinal());
                    str = "need_independent_process";
                    if (cVar.K) {
                        i2 = 1;
                    }
                    jSONObject.put(str, i2);
                    str = "head_connection_error_msg";
                    Object obj = cVar.m0;
                    if (obj == null) {
                        obj = "";
                    }
                    jSONObject.put(str, obj);
                    str = "extra";
                    obj = cVar.h;
                    if (obj == null) {
                        obj = "";
                    }
                    jSONObject.put(str, obj);
                    jSONObject.put("add_listener_to_same_task", cVar.w0);
                    List list = cVar.s;
                    if (list != null) {
                        jSONObject.put("backup_url_count", list.size());
                        jSONObject.put("cur_backup_url_index", cVar.P);
                    }
                    list = cVar.j0;
                    if (list != null) {
                        jSONObject.put("forbidden_urls", list.toString());
                    }
                }
                if (aVar != null) {
                    jSONObject.put("error_code", aVar.a);
                    jSONObject.put("error_msg", aVar.b);
                }
            } catch (JSONException e2) {
                e = e2;
                e.printStackTrace();
                return jSONObject;
            }
        } catch (JSONException e3) {
            e = e3;
            jSONObject = null;
            e.printStackTrace();
            return jSONObject;
        }
        return jSONObject;
    }

    public static void l(int i, SparseArray<c.j.a.d.b.d.b> sparseArray, boolean z, c cVar, com.ss.android.socialbase.downloader.e.a aVar) {
        if (z && sparseArray != null) {
            try {
                if (sparseArray.size() > 0) {
                    SparseArray clone;
                    synchronized (sparseArray) {
                        clone = sparseArray.clone();
                    }
                    for (int i2 = 0; i2 < clone.size(); i2++) {
                        c.j.a.d.b.d.b bVar = (c.j.a.d.b.d.b) clone.get(clone.keyAt(i2));
                        if (bVar != null) {
                            if (i == 1) {
                                bVar.a(cVar);
                            } else if (i == 2) {
                                bVar.b(cVar);
                            } else if (i == 4) {
                                bVar.c(cVar);
                            } else if (i == 5) {
                                bVar.R(cVar, aVar);
                            } else if (i == 6) {
                                bVar.u(cVar);
                            } else if (i == 7) {
                                bVar.N(cVar, aVar);
                            } else if (i != 11) {
                                switch (i) {
                                    case BaseCode.DATA_NULL_IN_INTENT /*-7*/:
                                        if (!(bVar instanceof p)) {
                                            break;
                                        }
                                        p pVar = (p) bVar;
                                        if (c.j.a.d.b.g.a.b() && cVar != null) {
                                            String str = p.a;
                                            StringBuilder stringBuilder = new StringBuilder();
                                            stringBuilder.append(" onIntercept -- ");
                                            stringBuilder.append(cVar.b);
                                            c.j.a.d.b.g.a.d(str, stringBuilder.toString());
                                            break;
                                        }
                                    case BaseCode.TRANSACTION_IS_NULL /*-6*/:
                                        bVar.A(cVar);
                                        break;
                                    case BaseCode.URI_IS_NULL /*-5*/:
                                    case -2:
                                        bVar.x(cVar);
                                        break;
                                    case BaseCode.NO_SOLUTION /*-4*/:
                                        bVar.H(cVar);
                                        break;
                                    case -3:
                                        bVar.D(cVar);
                                        break;
                                    case -1:
                                        bVar.z(cVar, aVar);
                                        break;
                                    default:
                                        break;
                                }
                            } else if (bVar instanceof g0) {
                                ((g0) bVar).P(cVar);
                            }
                        }
                    }
                }
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
    }

    public static final void m(c.j.a.d.a.k.a.c cVar, int i) throws IOException {
        int a = cVar.a();
        if (a != i) {
            StringBuilder g = c.b.a.a.a.g("Expected chunk of type 0x");
            g.append(Integer.toHexString(i));
            g.append(", read 0x");
            g.append(Integer.toHexString(a));
            g.append(".");
            throw new IOException(g.toString());
        }
    }

    public static void n(q qVar, c cVar, com.ss.android.socialbase.downloader.e.a aVar, int i) {
        if (qVar != null) {
            try {
                JSONObject k = k(qVar.c(), cVar, aVar, i);
                if (k == null) {
                    k = new JSONObject();
                }
                qVar.a(k);
            } catch (Throwable unused) {
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:49:0x00b7 A:{Catch:{ JSONException -> 0x00df }} */
    /* JADX WARNING: Removed duplicated region for block: B:63:0x00f4 A:{Catch:{ all -> 0x002a, all -> 0x00fa }} */
    /* JADX WARNING: Missing exception handler attribute for start block: B:44:0x0087 */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    public static void o(c.j.a.d.b.i.f r13, java.lang.String r14, long r15, java.lang.String r17, int r18, java.io.IOException r19, com.ss.android.socialbase.downloader.g.c r20) {
        /*
        r1 = r19;
        r2 = r20;
        r3 = "setting_tag";
        if (r2 != 0) goto L_0x0009;
    L_0x0008:
        return;
    L_0x0009:
        r0 = r20.g0();
        r4 = c.j.a.d.b.l.a.d(r0);
        r5 = 0;
        r0 = "monitor_download_connect";
        r6 = r4.b(r0, r5);
        if (r6 > 0) goto L_0x001b;
    L_0x001a:
        return;
    L_0x001b:
        r0 = android.text.TextUtils.isEmpty(r14);
        if (r0 == 0) goto L_0x0022;
    L_0x0021:
        return;
    L_0x0022:
        r7 = -1;
        if (r13 == 0) goto L_0x002f;
    L_0x0025:
        r7 = r13.b();	 Catch:{ all -> 0x002a }
        goto L_0x002f;
    L_0x002a:
        r0 = move-exception;
        r8 = r0;
        r8.printStackTrace();	 Catch:{ all -> 0x00fa }
    L_0x002f:
        r8 = "";
        r0 = 400; // 0x190 float:5.6E-43 double:1.976E-321;
        r9 = 200; // 0xc8 float:2.8E-43 double:9.9E-322;
        r10 = 0;
        if (r7 < r9) goto L_0x003a;
    L_0x0038:
        if (r7 < r0) goto L_0x005e;
    L_0x003a:
        r11 = r2.F;	 Catch:{ all -> 0x00fa }
        if (r11 == 0) goto L_0x0045;
    L_0x003e:
        r11 = r2.n0;	 Catch:{ all -> 0x00fa }
        if (r11 < r9) goto L_0x0044;
    L_0x0042:
        if (r11 < r0) goto L_0x0045;
    L_0x0044:
        return;
    L_0x0045:
        if (r1 == 0) goto L_0x005e;
    L_0x0047:
        r0 = c.j.a.d.b.e.b.a();	 Catch:{ all -> 0x00fa }
        r0 = c.j.a.d.b.n.a.G(r0);	 Catch:{ all -> 0x00fa }
        if (r0 != 0) goto L_0x0054;
    L_0x0051:
        r7 = 1049; // 0x419 float:1.47E-42 double:5.183E-321;
        goto L_0x005e;
    L_0x0054:
        c.j.a.d.b.n.a.o(r1, r8);	 Catch:{ a -> 0x0058 }
        throw r10;
    L_0x0058:
        r0 = move-exception;
        r1 = r0;
        r7 = r1.a;	 Catch:{ all -> 0x00fa }
        r10 = r1.b;	 Catch:{ all -> 0x00fa }
    L_0x005e:
        r0 = android.net.Uri.parse(r14);	 Catch:{ all -> 0x00fa }
        r1 = r0.getHost();	 Catch:{ all -> 0x00fa }
        r9 = r0.getPath();	 Catch:{ all -> 0x00fa }
        r0 = r0.getLastPathSegment();	 Catch:{ all -> 0x00fa }
        r11 = android.text.TextUtils.isEmpty(r9);	 Catch:{ all -> 0x00fa }
        if (r11 != 0) goto L_0x0087;
    L_0x0074:
        r11 = android.text.TextUtils.isEmpty(r0);	 Catch:{ all -> 0x00fa }
        if (r11 != 0) goto L_0x0087;
    L_0x007a:
        r11 = r9.length();	 Catch:{ all -> 0x0087 }
        r12 = r0.length();	 Catch:{ all -> 0x0087 }
        r11 = r11 - r12;
        r9 = r9.substring(r5, r11);	 Catch:{ all -> 0x0087 }
    L_0x0087:
        r5 = new org.json.JSONObject;	 Catch:{ all -> 0x00fa }
        r5.<init>();	 Catch:{ all -> 0x00fa }
        r8 = r4.g(r3, r8);	 Catch:{ JSONException -> 0x00df }
        r5.put(r3, r8);	 Catch:{ JSONException -> 0x00df }
        r3 = "url_host";
        r5.put(r3, r1);	 Catch:{ JSONException -> 0x00df }
        r1 = "url_path";
        r5.put(r1, r9);	 Catch:{ JSONException -> 0x00df }
        r1 = "url_file";
        r5.put(r1, r0);	 Catch:{ JSONException -> 0x00df }
        r0 = "net_lib";
        r1 = r18;
        r5.put(r0, r1);	 Catch:{ JSONException -> 0x00df }
        r0 = "connect_type";
        r1 = r17;
        r5.put(r0, r1);	 Catch:{ JSONException -> 0x00df }
        r0 = "status_code";
        r5.put(r0, r7);	 Catch:{ JSONException -> 0x00df }
        if (r10 == 0) goto L_0x00c8;
    L_0x00b7:
        r0 = "exception_msg_length";
        r1 = 500; // 0x1f4 float:7.0E-43 double:2.47E-321;
        r0 = r4.b(r0, r1);	 Catch:{ JSONException -> 0x00df }
        r1 = "err_msg";
        r0 = c.j.a.d.b.n.a.f(r10, r0);	 Catch:{ JSONException -> 0x00df }
        r5.put(r1, r0);	 Catch:{ JSONException -> 0x00df }
    L_0x00c8:
        r0 = "connect_time";
        r3 = r15;
        r5.put(r0, r3);	 Catch:{ JSONException -> 0x00df }
        r0 = "pkg_name";
        r1 = r2.w;	 Catch:{ JSONException -> 0x00df }
        r5.put(r0, r1);	 Catch:{ JSONException -> 0x00df }
        r0 = "name";
        r1 = r20.j0();	 Catch:{ JSONException -> 0x00df }
        r5.put(r0, r1);	 Catch:{ JSONException -> 0x00df }
        goto L_0x00e3;
    L_0x00df:
        r0 = move-exception;
        r0.printStackTrace();	 Catch:{ all -> 0x00fa }
    L_0x00e3:
        r0 = 1;
        r1 = 3;
        if (r6 == r0) goto L_0x00e9;
    L_0x00e7:
        if (r6 != r1) goto L_0x00eb;
    L_0x00e9:
        r0 = c.j.a.d.b.e.b.a;	 Catch:{ all -> 0x00fa }
    L_0x00eb:
        r0 = 2;
        if (r6 == r0) goto L_0x00f0;
    L_0x00ee:
        if (r6 != r1) goto L_0x00fe;
    L_0x00f0:
        r0 = c.j.a.d.b.e.b.Q;	 Catch:{ all -> 0x00fa }
        if (r0 == 0) goto L_0x00fe;
    L_0x00f4:
        r1 = "download_connect";
        r0.a(r2, r1, r5);	 Catch:{ all -> 0x00fa }
        goto L_0x00fe;
    L_0x00fa:
        r0 = move-exception;
        r0.printStackTrace();
    L_0x00fe:
        return;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.j.a.c.y.a.i.o(c.j.a.d.b.i.f, java.lang.String, long, java.lang.String, int, java.io.IOException, com.ss.android.socialbase.downloader.g.c):void");
    }

    public static void p(boolean z) {
        String str = "key_install_finish_hijack";
        String str2 = "key_install_finish";
        String w = w(System.currentTimeMillis());
        SharedPreferences sharedPreferences = y.a().getSharedPreferences("sp_install_guide", 0);
        try {
            JSONObject jSONObject = new JSONObject(sharedPreferences.getString(w, "{}"));
            jSONObject.putOpt(str2, Integer.valueOf(jSONObject.optInt(str2) + 1));
            if (z) {
                jSONObject.putOpt(str, Integer.valueOf(jSONObject.optInt(str) + 1));
            }
            Editor edit = sharedPreferences.edit();
            edit.putString(w, jSONObject.toString());
            edit.apply();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public static boolean q(Context context, String str, String str2) {
        try {
            for (ServiceInfo serviceInfo : context.getPackageManager().getPackageInfo(str, 4).services) {
                if (serviceInfo.exported && serviceInfo.enabled && serviceInfo.permission == null && serviceInfo.name.equals(str2)) {
                    return true;
                }
            }
        } catch (Throwable th) {
            th.printStackTrace();
        }
        return false;
    }

    public static String r(int i) {
        if (i == 449) {
            return "Retry With";
        }
        if (i == 451) {
            return "Unavailable For Legal Reasons";
        }
        if (i == 600) {
            return "Unparseable Response Headers";
        }
        if (i == 509) {
            return "Bandwidth Limit Exceeded";
        }
        if (i == 510) {
            return "Not Extended";
        }
        switch (i) {
            case DialogButton.CANCEL /*100*/:
                return "Continue";
            case DialogButton.CONFIRM /*101*/:
                return "Switching Protocols";
            case 102:
                return "Processing";
            default:
                switch (i) {
                    case AGCServerException.OK /*200*/:
                        return "OK";
                    case 201:
                        return "Created";
                    case 202:
                        return "Accepted";
                    case 203:
                        return "Non-Authoritative Information";
                    case 204:
                        return "No Content";
                    case 205:
                        return "Reset Content";
                    case 206:
                        return "Partial Content";
                    case 207:
                        return "Multi-Status";
                    default:
                        switch (i) {
                            case 300:
                                return "Multiple Choices";
                            case 301:
                                return "Moved Permanently";
                            case 302:
                                return "Move Temporarily";
                            case 303:
                                return "See Other";
                            case 304:
                                return "Not Modified";
                            case 305:
                                return "Use Proxy";
                            case 306:
                                return "Switch Proxy";
                            case 307:
                                return "Temporary Redirect";
                            default:
                                switch (i) {
                                    case AGCServerException.AUTHENTICATION_INVALID /*400*/:
                                        return "Bad Request";
                                    case AGCServerException.TOKEN_INVALID /*401*/:
                                        return "Unauthorized";
                                    case 402:
                                        return "Payment Required";
                                    case AGCServerException.AUTHENTICATION_FAILED /*403*/:
                                        return "Forbidden";
                                    case 404:
                                        return "Not Found";
                                    case 405:
                                        return "Method Not Allowed";
                                    case 406:
                                        return "Not Acceptable";
                                    case 407:
                                        return "Proxy Authentication Required";
                                    case 408:
                                        return "Request Timeout";
                                    case 409:
                                        return "Conflict";
                                    case 410:
                                        return "Gone";
                                    case 411:
                                        return "Length Required";
                                    case 412:
                                        return "Precondition Failed";
                                    case 413:
                                        return "Request Entity Too Large";
                                    case 414:
                                        return "Request-URI Too Long";
                                    case 415:
                                        return "Unsupported Media Type";
                                    case 416:
                                        return "Requested Range Not Satisfiable";
                                    case 417:
                                        return "Expectation Failed";
                                    case 418:
                                        return "I'm a teapot";
                                    default:
                                        switch (i) {
                                            case 421:
                                                return "Too Many Connections";
                                            case 422:
                                                return "Unprocessable Entity";
                                            case 423:
                                                return "Locked";
                                            case 424:
                                                return "Failed Dependency";
                                            case 425:
                                                return "Unordered Collection";
                                            case 426:
                                                return "Upgrade Required";
                                            default:
                                                switch (i) {
                                                    case AGCServerException.UNKNOW_EXCEPTION /*500*/:
                                                        return "Internal Server Error";
                                                    case 501:
                                                        return "Not Implemented";
                                                    case 502:
                                                        return "Bad Gateway";
                                                    case AGCServerException.SERVER_NOT_AVAILABLE /*503*/:
                                                        return "Service Unavailable";
                                                    case 504:
                                                        return "Gateway Timeout";
                                                    case 505:
                                                        return "HTTP Version Not Supported";
                                                    case 506:
                                                        return "Variant Also Negotiates";
                                                    case 507:
                                                        return "Insufficient Storage";
                                                    default:
                                                        return "";
                                                }
                                        }
                                }
                        }
                }
        }
    }

    public static boolean s(int i) {
        return (b.O & i) == i;
    }

    public static int t(String str) {
        return a(b.a(), str);
    }

    public static int u(String str, String str2) {
        try {
            return b.a().getResources().getIdentifier(str, "attr", str2);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    public static PackageInfo v(Context context, File file, int i) {
        PackageManager packageManager = context.getPackageManager();
        if (packageManager == null) {
            context = b.a;
            return null;
        }
        try {
            return packageManager.getPackageArchiveInfo(file.getPath(), i);
        } catch (Throwable th) {
            th.getMessage();
            context = b.a;
            return null;
        }
    }

    public static String w(long j) {
        Calendar instance = Calendar.getInstance();
        instance.setTimeInMillis(j);
        int i = instance.get(1);
        int i2 = instance.get(2);
        int i3 = instance.get(5);
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(i);
        String str = "-";
        stringBuilder.append(str);
        stringBuilder.append(i2);
        stringBuilder.append(str);
        stringBuilder.append(i3);
        return stringBuilder.toString();
    }

    public static boolean x(int i) {
        return (i <= 0 || i == 7 || i == 8) ? false : true;
    }

    public static int y(String str) {
        return Log.d("greenDAO", str);
    }

    public static int z(String str) {
        try {
            return b.a().getResources().getIdentifier(str, "id", b.a().getPackageName());
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
}
